﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;
using DTO;

namespace GUI
{
    public partial class frmXuatHoaDon : Form
    {
        private int MaPhieu = 0;
        private double TongTien = 0;
        private DateTime KetThuc;

        public frmXuatHoaDon()
        {
            InitializeComponent();
        }

        public frmXuatHoaDon(int MaPhieu)
        {
            // TODO: Complete member initialization
            this.MaPhieu = MaPhieu;
            InitializeComponent();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmThanhToan_Load(object sender, EventArgs e)
        {
            PhieuThueInfo p = new PhieuThueInfo();
            p = PhieuThuePhongBUS.LayPhieuThuePhong(this.MaPhieu);
            double totaltime = 0;
            this.KetThuc = (p.NgayKT < DateTime.Now ? DateTime.Now : p.NgayKT);
            totaltime = (this.KetThuc - p.NgayBD).TotalHours;
            this.lblSTT.Text = MaPhieu.ToString();
            this.lblPhong.Text = p.TenPhong;
            this.lblKhachHang.Text = p.HoTen;
            this.lblDiaChi.Text = p.DiaChi;
            this.lblSoGioThue.Text = Math.Round(totaltime,0).ToString() + " Giờ";
            this.lblFromTo.Text = "(" + p.NgayBD.ToString() + " -> " + this.KetThuc.ToString() + " )";
            this.lblDonGia.Text = String.Format("{0:c}", p.Gia);
            this.lblUngTruoc.Text = String.Format("{0:c}", p.TienDatCoc);
            this.TongTien = Math.Round((totaltime * p.Gia), 0) - p.TienDatCoc;
            this.lblTongTien.Text = String.Format("{0:c}", this.TongTien);
        }

        private void btnThanhToan_Click(object sender, EventArgs e)
        {
            HoaDonBUS.ThemHoaDon(this.MaPhieu, this.TongTien, this.KetThuc);
        }
    }
}
